<?php
class ArticleController extends HomeController{
    public function postAction(){
        $id = Request::asget(3,'id',1);
        $model = new ArticleModel;
        $data = $model->where(['id'=>$id])->one();
        $this->_view->article = $data;
        $model = new CommentModel;
        $this->_view->comment = $model->comment_article_list($id);
    }
    public function searchAction(){
        $keyword = Request::asget(6,'keyword','');
        if($this->_request->isPost() || $keyword == ''){
            return false;
        }else{
            $where = ['title like '=> '%'.$keyword.'%'];
            $model = new ArticleModel;
            $count = $model->where($where)->count();
            $result = $model->where($where)->limit(10)->select();
            $this->_view->count = $count;
            $this->_view->keyword = $keyword;
            $this->_view->articles = $result;
        }
    }
    public function pageAction(){
        $keyword = Request::asget(6,'keyword','');
        if($this->_request->isPost() || $keyword == ''){
            return false;
        }else{
            $page = Request::asget(3,'page',0);
            $where = ['title like '=> '%'.$keyword.'%'];
            $model = new ArticleModel;
            $result = $model->where($where)->limit($page,10)->select();
            $data = [
                'articles'=>$result,
            ];
            Yaf_Dispatcher::getInstance()->disableView();
            $this->display('page',$data);
        }
    }

}